<template>
  <div class="login-container">
    <div class="logo" />
    <div class="form">
      <h1>智慧园区-登录</h1>
      <el-card shadow="never" class="login-card">
        <!--登录表单-->
        <el-form ref="loginForm" :model="loginForm" :rules="loginRules">
          <div class="title">账号</div>
          <el-form-item prop="mobile">
            <!-- 用户名 -->
            <el-input v-model="loginForm.mobile" placeholder="请输入手机号" />
          </el-form-item>
          <div class="title">密码</div>
          <el-form-item prop="password">
            <!-- 密码 -->
            <el-input v-model="loginForm.password" placeholder="请输入密码" show-password />
          </el-form-item>
          <div class="title">模型uuid</div>
          <el-form-item prop="uuid">
            <!-- 模型uuid -->
            <el-input v-model="loginForm.uuid" placeholder="请输入uuid" show-password />
          </el-form-item>
          <el-form-item prop="isAgree">
            <el-checkbox v-model="loginForm.isAgree">
              记住我
            </el-checkbox>
          </el-form-item>
          <el-form-item>
            <el-button style="width: 350px;" type="primary" @click="login">登录</el-button>
          </el-form-item>
          <p class="warn">仅用于IT培训教学使用，为保障您的个人信息安全，请勿向平台录入任何个人敏感信息（如手机号、身份证号等）！</p>
        </el-form>
      </el-card>
    </div>
  </div>
</template>
<script>
// import service from '@/utils/request'
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        mobile: 'demo',
        password: 'Hmzs%001',
        isAgree: false,
        uuid: ''
      },
      loginRules: {
        mobile: [
          { required: true, message: '请输入用户名', trigger: 'change' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 16, message: '密码需要6-16位', trigger: 'change' }
        ],
        uuid: [
          { required: true, message: '请输入uuid', trigger: 'blur' }
          // { min: 6, max: 16, message: 'uid需要6-16位', trigger: 'change' },
          // { pattern: /^.{6,16}$/, message: 'uid需要6-16位', trigger: 'change' }
        ],
        isAgree: [
          {
            validator(rule, value, callback) {
              value ? callback() : callback(new Error('请勾选用户协议'))
            }
          }
        ]
      }

    }
  },
  methods: {
    async login() {
      // this.$refs.loginForm.validate((isOK) => {
      //   alert('校验通过')
      // })
      try {
        await this.$refs.loginForm.validate()
        // alert('通过')
        await this.$store.dispatch('user/login', { username: this.loginForm.mobile, password: this.loginForm.password })
        // service.post('/park/login', this.loginForm)
        this.$router.push('/')
      } catch (error) {
        console.log(error)
      }
    }
  }

}
</script>
<style lang="scss">
.login-container {
  display: flex;
  align-items: stretch;
  width: 100vw;
  height: 99vh;
  .logo {
    flex: 3;
    background: rgba(38, 72, 176) url(../../assets/common/loginsmart.svg)
      no-repeat center / cover;
    border-top-right-radius: 40px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    padding: 0 100px;
    .icon {
      background: url(../../assets/common/logo.png) no-repeat 70px center /
        contain;
      width: 300px;
      height: 50px;
      margin-bottom: 50px;
    }
    p {
      color: #fff;
      font-size: 18px;
      margin-top: 20px;
      width: 300px;
      text-align: center;
    }
  }
  .form {
    flex: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: 150px;

    .el-card {
      border: none;
      padding: 0;
      .title{
        font-size: 20px;
        margin-top:40px ;
        margin-bottom:10px ;
        color: #8b929d;
      }
    }
    h1 {
      padding-left: 20px;
      font-size: 33px;
      font-weight: 500;
      padding-bottom: 5px;
    }
    .el-input {
      width: 350px;
      height: 44px;
      .el-input__inner {
        background: #f4f5fb;
      }
    }
    .warn{
      color: red;
      width: 350px;
      font-size: 17px;
    }
    // .el-checkbox {
    //   font-size: 20px;
    //   color:#606266;
    // }
  }
}
</style>
